package org.arabidopsis.test;


import java.io.*;
import java.util.*;

import org.biojava.bio.program.sax.*;
import org.biojava.bio.program.ssbind.*;
import org.biojava.bio.search.*;
import org.biojava.bio.program.sax.blastxml.BlastXMLParserFacade;
import org.biojava.bio.seq.db.*;
import org.xml.sax.*;
import org.biojava.bio.*;

//input /home/ozgur/brenda/tempresult.xml or
//		input.xml
public class BlastJoin {
  /**
   * args[0] is assumed to be the name of a Blast output file
   */
	String executable = "blastall ";
	String programType = "-p blastp " ;
	String databaseLoc = "-d /home/ozgur/brenda/brAll "; 
	String queryFiles = "-i /home/ozgur/brenda/tester "; 
	String options = "-b 300 -m 7";
	OutputStream outS=System.out;
	
	BlastJoin(OutputStream alignmentStream)
	{
		this.outS=alignmentStream;
	}
	
	public static void main(String[] args) {
  	(new BlastJoin()).test();
  }
  
  
  void test(){
	
	  try {
    	Runtime rt = Runtime.getRuntime();
			//Process proc = rt.exec ("/home/ozgur/brenda/.blast");
    	Process proc = 
				rt.exec (executable + programType + databaseLoc + queryFiles + options);
/*    	OutputStream fout = proc.getOutputStream();
    	OutputStream bout= new BufferedOutputStream(fout);
    	OutputStreamWriter out = new OutputStreamWriter(bout);
    	String searchSeq=">mytest | 19.19.19.11 | species species\n"+
		"MATAGKVIKCKAAVAWAAGKPLSIEEVEVAPPQAMEVRVKILFTSLCHTDVYFWEAKGQT\n" +
		"PVFPRIFGHEAGGIIESVAEGVTDVAPGDHVLPVFTGECKECAHCKSAESNMCDLLRINT\n" +
		"DRGVMIADGKSRFSINGKAIYHFVGTSTFSEYTVMHVGCVAKINPQAPLDKVCVLSCGYS\n" +
		"TGLGASINVAKPPKGSTVAVFGLGAVGLAAAEGARIAGASRIIGVDLNPSRFEEARKFGC\n" +
		"TEFVNPKDHNKPVQEVLAAMTNGGVDRSVECTGNINAMIQAFECVHDGWGVAVLVGVPHK\n" +
		"DAEFKTHPMNFLNERTLKATFFGNYKPRTDLPNVVELYMKKELEVEKFITHSVPFAEINK\n" +
		"AFDLMAKGEGIRCIIRMEA\n";
    	out.write(searchSeq);*/

    	//InputStream fin;
    	/*String searchSeq=">mytest | 19.19.19.11 | species species\n"+
		"MATAGKVIKCKAAVAWAAGKPLSIEEVEVAPPQAMEVRVKILFTSLCHTDVYFWEAKGQT\n" +
		"PVFPRIFGHEAGGIIESVAEGVTDVAPGDHVLPVFTGECKECAHCKSAESNMCDLLRINT\n" +
		"DRGVMIADGKSRFSINGKAIYHFVGTSTFSEYTVMHVGCVAKINPQAPLDKVCVLSCGYS\n" +
		"TGLGASINVAKPPKGSTVAVFGLGAVGLAAAEGARIAGASRIIGVDLNPSRFEEARKFGC\n" +
		"TEFVNPKDHNKPVQEVLAAMTNGGVDRSVECTGNINAMIQAFECVHDGWGVAVLVGVPHK\n" +
		"DAEFKTHPMNFLNERTLKATFFGNYKPRTDLPNVVELYMKKELEVEKFITHSVPFAEINK\n" +
		"AFDLMAKGEGIRCIIRMEA\n";*/
/*
>mytest | 19.19.19.11 | species species
MATAGKVIKCKAAVAWAAGKPLSIEEVEVAPPQAMEVRVKILFTSLCHTDVYFWEAKGQT
PVFPRIFGHEAGGIIESVAEGVTDVAPGDHVLPVFTGECKECAHCKSAESNMCDLLRINT
DRGVMIADGKSRFSINGKAIYHFVGTSTFSEYTVMHVGCVAKINPQAPLDKVCVLSCGYS
TGLGASINVAKPPKGSTVAVFGLGAVGLAAAEGARIAGASRIIGVDLNPSRFEEARKFGC
TEFVNPKDHNKPVQEVLAAMTNGGVDRSVECTGNINAMIQAFECVHDGWGVAVLVGVPHK
DAEFKTHPMNFLNERTLKATFFGNYKPRTDLPNVVELYMKKELEVEKFITHSVPFAEINK
AFDLMAKGEGIRCIIRMEA
*/    	
		// any error from the process?
        StreamHandler errorStream = new  StreamHandler(proc.getErrorStream(), System.err);
        
        // any output from the process?
        StreamHandler outputStream = new StreamHandler(proc.getInputStream(), outS);
            
        // any input to the process?
        StreamHandler inputStream = new StreamHandler(System.in, proc.getOutputStream());
        
        // start the stream threads
        errorStream.start();
        outputStream.start();
        inputStream.start();
                                
        // wait till it returns
        int exitVal = proc.waitFor();
        
        System.exit(exitVal);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
  }
  
  